package com.ghck.server.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import cn.jpush.api.schedule.ScheduleResult;

public class JPushUtils {
	
	private static final Logger logger = LoggerFactory.getLogger(JPushUtils.class);
	
	private static final String APP_KEY = "bf8a9357248e4be0edcf8a36";
	
	private static final String MAST_SECRET = "be9b15b9882ff63f1d9160d0";
	private static JPushClient jpushClient = null;
	
	static{
		jpushClient = new JPushClient(MAST_SECRET, APP_KEY);
	}
	/**
	 * notification	可选	通知内容体。是被推送到客户端的内容。与 message 一起二者必须有其一，可以二者并存
	 * message	可选	消息内容体。是被推送到客户端的内容。与 notification 一起二者必须有其一，可以二者并存
	 * @param notification
	 * @param message
	 */
	public static PushPayload buildPushMessage(String alert, String msgContent) {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.all())
				.setNotification(Notification.newBuilder().setAlert(alert).build())
				// .setNotification(Notification.newBuilder()
				// .addPlatformNotification(IosNotification.newBuilder()
				// .setAlert(ALERT)
				// .setBadge(5)
				// .setSound("happy")
				// .addExtra("from", "JPush")
				// .build())
				// .build())
				.setMessage(Message.content(msgContent))
				.setOptions(Options.newBuilder().setApnsProduction(true).build()).build();
	}
	

}
